//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.pss;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.PssPurcReturnDao;
import com.aidong.model.wills.PssPurcReturnImpl;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"purcReturnRpt"})
public class PurcReturnRptController extends BaseController {
    @Resource
    PssPurcReturnDao pssPurcReturnDao;

    public PurcReturnRptController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        ModelAndView mv = new ModelAndView("pss/purcreturnrpt/list");
        mv.addObject("shopName", this.getTypeList("shopName"));
        mv.addObject("providerList", this.getTypeList("providerList"));
        return mv;
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "providerCode",required = false) String providerCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "shopcode", shopCode);
        if(!this.chkNull(providerCode)) {
            cd.eq("providerCode", providerCode);
        }

        if(!this.chkNull(dateFrom)) {
            cd.ge("ReturnDate", this.parseDate(dateFrom, "yyyy-MM-dd"));
        }

        if(!this.chkNull(dateTo)) {
            cd.le("ReturnDate", this.parseDate(dateTo + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
        }

        this.pssPurcReturnDao.getPurcReturnRptList(pg, cd);
        ModelAndView mv = new ModelAndView("pss/purcreturnrpt/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("shopName", this.getTypeList("shopName"));
        mv.addObject("providerList", this.getTypeList("providerList"));
        mv.addObject("productUnit", this.getTypeList("productUnit"));
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "providerCode",required = false) String providerCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, 20000);
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "shopcode", shopCode);
            if(!this.chkNull(providerCode)) {
                cd.eq("providerCode", providerCode);
            }

            if(!this.chkNull(dateFrom)) {
                cd.ge("ReturnDate", this.parseDate(dateFrom, "yyyy-MM-dd"));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("ReturnDate", this.parseDate(dateTo + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
            }

            this.pssPurcReturnDao.getPurcReturnRptList(e, cd);
            ExportXls xls = new ExportXls(response, "采购退货汇总", "采购退货汇总");
            xls.addHead(new String[]{"门店编号", "门店名称", "合同编号", "供应商", "商品编码", "商品名称", "数量", "金额", "退货时间", "操作员"});
            xls.setWidth(new int[]{10, 25, 10, 25, 10, 25, 10, 10, 10, 10});
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                PssPurcReturnImpl puot = (PssPurcReturnImpl)i$.next();
                xls.addRow(new Object[]{puot.getShopCode(), this.cache.getValue("shopName", puot.getShopCode()), puot.getDefaultContract(), this.cache.getValue("providerList", puot.getProviderCode()), puot.getProductCode(), this.cache.getValue("ProductcodeList", puot.getProductCode()), puot.getQuantity(), puot.getAmount(), puot.getReturnDate(), this.cache.getValue("userName", puot.getCreateuser())});
            }

            xls.close();
            this.addUserLog("导出采购入库汇总", e.getResultList().size() + "条记录");
        } catch (Exception var11) {
            this.log.error("import", var11);
        }

        return null;
    }
}
